home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
async1.zip
/
ASYNC.ASM
next >
Wrap
Assembly Source File
|
1985-09-13
|
26KB
|
546 lines
Page 60,132
.Radix 16
Title Communications Interface Routine
Subttl Macros
Page
Save Macro R1,R2,R3,R4,R5,R6,R7,R8,R9,R10
Irp Rx,<R1,R2,R3,R4,R5,R6,R7,R8,R9,R10> ;Repeat for each parm
Ifnb <Rx> ;If this parm not blank
Push Rx ;Save the register
Endif ;End Ifnb
Endm ;End Irp
;; The Restore macro makes use of the fact that R1-R10 are still defined,
;; but, being a different macro, this will not expand when the Save macro
;; is used. Note that the Restore macro will restore whatever registers
;; were last Save'd in the assembly listing, not during execution.
;; Therefore, its use is restricted to restoring the previous sequential
;; Save macro's registers.
Restore Macro
Irp Rx,<R10,R9,R8,R7,R6,R5,R4,R3,R2,R1> ;Repeat for each parm
Ifnb <Rx> ;If this parm not blank
Pop Rx ;Pop the register
Endif ;End Ifnb
Endm ;End Irp
Endm ;End of Restore macro
Endm ;End of Save Macro
Setint Macro Vector,Routine ;Sets an interrupt vector
Lea DX,Routine ;Address the routine
Mov AX,25*100+Vector ;Set the vector
Int 21 ;Call DOS to do it
Endm
Incbuf Macro Buffer
Local Notend ;Not at end of buffer label
;; Macro to increment the buffer pointer. This macro is used
;; internally by other buffer processing macros. The pointer to
;; be incremented must be in BX. Results in BX.
Inc BX ;Point at next character
Cmp BX,Offset Buffer.Buff + Length Buff ;At end of buffer?
Jb Notend ;No - continue
Lea BX,Buffer.Buff ;Point back to start of buffer
Notend Label Near ;Not at end of buffer
Endm ;End of macro
Bufinit Macro Buffer ;Initialize the buffers
;; This macro must be called once for each buffer. It's purpose
;; is to ensure the pointers are set up correctly before the
;; buffers are used. Unless the buffers are initialized, the
;; results will be unpredictable.
Lea BX,Buffer.Buff ;Get address of buffer
Mov Buffer.Staptr,BX ;Set start of data address
Mov Buffer.Endptr,BX ;End of data too (buffer empty)
Endm ;End of macro
Putbuf Macro Buffer ;Insert a character in the buffer
Local Bufull
;; This macro puts a byte into BUFFER. Origin is AL, and it uses the
;; BX reg. The carry flag is set if the buffer is full and the routine
;; cannot place a bit in the buffer, and is cleared if the character is
;; inserted in the buffer and pointers updated.
;; The buffer must have been defined with the BUFFER structure.
Mov BX,Buffer.Endptr ;Get pointer to end of buffer
Incbuf Buffer ;Point at next character
Cmp BX,Buffer.Staptr ;Buffer full?
Je Bufull ;Yes - buffer overrun
Mov [BX],AL ;Store a byte
Mov Buffer.Endptr,BX ;Replace new pointer
Stc ;Inverse of carry flag returned
Bufull Label Near ;Get a character from the buffer
Cmc ;Invert carry bit for return code
Endm ;End of macro
Getbuf Macro Buffer ;Get a character from the buffer
Local Bufemp
;; This macro gets a character from BUFFER and returns it in AL. It
;; uses the BX reg. Carry flag is set if the buffer is empty, and
;; cleared if a character is returned in AL.
;; The buffer must have been defined with the BUFFER structure.
Mov BX,Buffer.Staptr ;Get buffer data start
Cmp BX,Buffer.Endptr ;Any data in buffer?
Je Bufemp ;Yes - go transmit it
Incbuf Buffer ;Point at next character
Mov AL,[BX] ;Get a byte
Mov Buffer.Staptr,BX ;Restore pointer
Stc ;Set complement of carry flag
Bufemp Label Near
Cmc ;Set true return flag
Endm
Flush Macro Buffer ;Flush the buffer
;; This macro will flush BUFFER by setting the start and end
;; pointers equal. It uses the BX reg.
Mov BX,Buffer.Staptr ;Get start of data
Mov Buffer.Endptr,BX ;Set end = start (empty)
Endm
; Structure used for buffer definition.
; Staptr = Endptr means buffer is full. Otherwise buffer has data
; in it.
Buffer Struc
Buff Db 256d Dup (0) ;Buffer size in decimal
Staptr Dw 0 ;Start of data pointer
Endptr Dw 0 ;End of data pointer
Buffer Ends
Inital Record Speed:3, Parity:2, Stop:1, Len:2 ;Init call parms in AL
Subttl Equates
Page
; Line status bits -- AH
Timeout Equ 80 ;Time out error
Tbufemp Equ 40 ;Transmit buffer empty
Tbufnfl Equ 20 ;Transmit buffer not full
Brkdet Equ 10 ;Break detect
Framerr Equ 08 ;Framing error
Parerr Equ 04 ;Parity error
Rcveovr Equ 02 ;Receive buffer overrun
Rdatrdy Equ 01 ;Receive buffer has data
; Modem status bits -- AL
Rlsd Equ 80 ;Received line signal detect
Ri Equ 40 ;Ring indicator
Dsr Equ 20 ;Data set ready
Cts Equ 10 ;Clear to send
Drlds Equ 08 ;Delta receive line signal detect
Teri Equ 04 ;Trailing edge ring indicator
Ddsr Equ 02 ;Delta data set ready
Dcts Equ 01 ;Delta clear to send
; Interrupt Enable reg bit definitions
Msint Equ 08 ;Modem status int bit
Rlsint Equ 04 ;Receive line status int bit
Thrint Equ 02 ;Transmit holding reg empty int bit
Daint Equ 01 ;Data availalbe interrupt
; Modem Control Port
Out2 Equ 08 ;Out2 bit
Out1 Equ 04 ;Out1 bit
Rts Equ 02 ;Request to Send
Dtr Equ 01 ;Data Terminal Ready
; Other equates and records
Asysmsk Equ 10 ;System interrupt (port 21) mask
Perror Equ -1 ;Paramater error
Baseadr Equ 3F8 ;Comm port 1 base address
Subttl Constants
Page +
Comm Segment Para Public 'Code'
Assume CS:Comm ,DS:Comm ,ES:nothing ,SS:Nothing
Org 100h ;Set starting point
Entry Label Near ;Initialization entry point
Jmp Start ;Go to initialization code
Db 'Asynchronous Communications Port Driver '